package ch.benjaminschuele.defytweaks;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.os.Handler;
import android.os.Message;

public class MainActivity extends Activity implements Runnable  {
    private static final String TAG = "DefyTweaks";
    private ProgressDialog pd;
    
	private OsTreat mOsTreat = new OsTreat();
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        
        Log.d(TAG,"This is a debug message");
        
        // Capture our button from layout
        Button button1 = (Button)findViewById(R.id.button1);
        // Register the onClick listener with the implementation above
        button1.setOnClickListener(mCorkyListener1); 
        
        // Capture our button from layout
        Button button2 = (Button)findViewById(R.id.button2);
        // Register the onClick listener with the implementation above
        button2.setOnClickListener(mCorkyListener2); 
  
//    	ch.benjaminschuele.defytweaks.OsTreat.SetStringXY("sfsfsafsaf asdf asdf");
        mOsTreat.SetStringXY("sfsfsafsaf asdf asdf");

//      mOsTreat.mStrPublic = "tesdf asdfsaf" ;
//      mOsTreat.SetStringXY("test skkdf sdf sdlsf");
    };

    // Create an anonymous implementation of OnClickListener
    private OnClickListener mCorkyListener1 = new OnClickListener() {
        public void onClick(View v) {
            Log.d(TAG,"On Click 1");
            
            TextView tv = (TextView)findViewById(R.id.TextOut1);
            
//            tv.setText(mOsTreat.GetStringXY());
            tv.setText("vor su");          
            
    		pd = ProgressDialog.show(MainActivity.this, "Working..", "Calculating su...", true,
    				false);

    		Thread thread = new Thread(MainActivity.this);
    		thread.start();
    		

            
        }
    };

    // Create an anonymous implementation of OnClickListener
    private OnClickListener mCorkyListener2 = new OnClickListener() {
        public void onClick(View v) {
            Log.d(TAG,"On Click 2");
            
            TextView tv = (TextView)findViewById(R.id.TextOut1);
            
            tv.setText("On Click 2   sdf sdf sfd sd");
            
        }
    };  
    
	public void run() 
	{
		Log.d(TAG,"run start");
		
        mOsTreat.TestSu();
        TextView tv = (TextView)findViewById(R.id.TextOut1);
        tv.setText("nach su");
		handler.sendEmptyMessage(0);
		
		Log.d(TAG,"run stop");
	}

	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			pd.dismiss();
			
			TextView tv = (TextView)findViewById(R.id.TextOut1);
			tv.setText("ende Aus die maus");

		}
	};
    
}